package com.yz.group1.group_1.controller;

import com.yz.group1.group_1.entity.AdminData;
import com.yz.group1.group_1.service.AdminDataService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
@RequestMapping({"/data"})
public class AdminDataController {
    @Autowired
    private AdminDataService adminDataService;

    public AdminDataController() {
    }

    @GetMapping
    public List<AdminData> adminDataList() {
        return this.adminDataService.listAllAdminDatas();
    }

    @PostMapping
    public boolean add(@RequestBody AdminData data) {
        return this.adminDataService.save(data);
    }

    @PutMapping({"/{id}"})
    public boolean update(@PathVariable Long id, @RequestBody AdminData data) {
        data.setId(id);
        return this.adminDataService.updateById(data);
    }

    @DeleteMapping({"/{id}"})
    public boolean delete(@PathVariable Long id) {
        return this.adminDataService.removeById(id);
    }
}
